$(document).ready(function() {
    //Everything is nicely encapsulated inside
    //this anonymous function
   
    //The class name of the required fields
    var REQUIRED_FIELD = "required_field";
    //The labels that display errors
    var LABELS = "required_field_message";
    //The form to prevent posting if input is missing
    var PREVENT_FORM = "prevent_post_form";
   
    var form = $("#" + PREVENT_FORM);
    if (form) {
       
	//Register a submit listener
	form.submit(function() {
	   
	    var labels = $("." + LABELS);
	    var fields = $("." + REQUIRED_FIELD);
	    var wasError = false;

	    for (var i=0; i < fields.length; i++) {
		if (fields[i].value == "") {		//Empty text
		    if (labels[i])
			$(labels[i]).show();		//Indicate error
		    wasError = true;
		} else if (labels[i])
		    $(labels[i]).hide();		//Hide the label if there was no error
	    }
	    return !wasError;	//Prevent the post if there was an error
	});
       
    }
   
});